package com.aaa.util;

import java.security.MessageDigest;

public class MD5 {
	private static char md5String[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
	'F' };

	/**
	 * @param pwd
	 * @return 杩斿洖MD5鍔犲瘑鍚庣殑瀵嗘枃
	 */
	public final static String MD5(String pwd) {
			try {
				//浣跨敤骞冲彴鐨勯粯璁ゅ瓧绗﹂泦灏嗘聽String聽缂栫爜涓郝燽yte搴忓垪锛屽苟灏嗙粨鏋滃瓨鍌ㄥ埌涓�釜鏂扮殑聽byte鏁扮粍涓�
				    byte[] btInput = pwd.getBytes();
				 
				//淇℃伅鎽樿鏄畨鍏ㄧ殑鍗曞悜鍝堝笇鍑芥暟锛屽畠鎺ユ敹浠绘剰澶у皬鐨勬暟鎹紝骞惰緭鍑哄浐瀹氶暱搴︾殑鍝堝笇鍊笺�
				    MessageDigest mdInst = MessageDigest.getInstance("MD5");
				//MessageDigest瀵硅薄閫氳繃浣跨敤聽update鏂规硶澶勭悊鏁版嵁锛屄犱娇鐢ㄦ寚瀹氱殑byte鏁扮粍鏇存柊鎽樿
				    mdInst.update(btInput);
				//聽鎽樿鏇存柊涔嬪悗锛岄�杩囪皟鐢╠igest锛堬級鎵ц鍝堝笇璁＄畻锛岃幏寰楀瘑鏂�
				    byte[] md = mdInst.digest();
				//聽鎶婂瘑鏂囪浆鎹㈡垚鍗佸叚杩涘埗鐨勫瓧绗︿覆褰㈠紡
				    int j = md.length;
				    char str[] = new char[j*2];
				    int k = 0;
				    for (int i = 0;i<j;i++) { //i聽=聽0
				        byte byte0 = md[i];//95
				        str[k++] = md5String[byte0 >>>4 & 0xf];//5聽
				        str[k++] = md5String[byte0 & 0xf];//聽F
				     }
				//杩斿洖缁忚繃鍔犲瘑鍚庣殑瀛楃涓�
				    return new String(str);
			    
			} catch (Exception e) {
				return null;
			}
		}
	
	/**判断字符串是否为空
	 * @param str
	 * @return
	 */
	public static boolean isEmpty(String str){
		
		if (null==str||str.equals("")||str.equals("null")) {
			return true;
		}
		
		return false;
	}
}


